// DailyQuestionController.java
package com.scuec.groupfive.Controller;

import com.scuec.groupfive.entity.QuestionInfo;
import com.scuec.groupfive.service.DailyQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/daily-question")
public class DailyQuestionController {

    @Autowired
    private DailyQuestionService dailyQuestionService;

    @GetMapping("/today")
    public QuestionInfo getTodayQuestion() {
        return dailyQuestionService.getTodayQuestion();
    }

    @PostMapping("/favorite")
    public int addToFavorites(@RequestParam Long userId,
                              @RequestParam Long questionId) {
        return dailyQuestionService.addToFavorites(userId, questionId);
    }

    @DeleteMapping("/favorite")
    public int removeFromFavorites(@RequestParam Long userId,
                                   @RequestParam Long questionId) {
        return dailyQuestionService.removeFromFavorites(userId, questionId);
    }

    @GetMapping("/favorite/check")
    public boolean isQuestionInFavorites(@RequestParam Long userId,
                                         @RequestParam Long questionId) {
        return dailyQuestionService.isQuestionInFavorites(userId, questionId);
    }

    @GetMapping("/answer")
    public Map<String, Object> getAnswerAndAnalysis(
            @RequestParam Long questionId,
            @RequestParam String questionType) {
        return dailyQuestionService.getAnswerAndAnalysis(questionId, questionType);
    }

    @PostMapping("/submit-answer")
    public int submitAnswer(@RequestParam Long userId,
                            @RequestParam Long questionId,
                            @RequestParam String questionType,
                            @RequestParam String answer,
                            @RequestParam Boolean isCorrect,
                            @RequestParam(required = false) Double score,
                            @RequestParam(required = false) Integer timeSpent) {
        return dailyQuestionService.submitAnswer(userId, questionId, questionType,
                answer, isCorrect, score, timeSpent);
    }
}